<?php

namespace Addons\Zmphoto\Controller;
use Addons\Zmphoto\Controller\BaseController;

class InfoReviewController extends BaseController{
	function _initialize() {
		parent::_initialize();
		$this->model = $this->getModel('photo_zm_review');
	}
    // 通用插件的列表模型
	public function lists() {
		$uid = I('uid',0,'intval');
        if($uid){
        	$map['aid'] = $uid;
        	session('common_condition',$map);
        }
        $where['token'] = get_token();
        $data = M('photo_zm_activity')->where($where)->field('id,actname as name')->select();
        $this->assign('uid',$uid);
		$this->assign('list_ctdata',$data);
		$list_data = $this->_get_model_list($this->model);
		$this->assign ( $list_data );
		$this->display('Zmphoto/custLists');
	}
	
	/*摄影师审核*/
	public function shen($id=null){
		$where['id'] = $id;
		if(M('photo_zm_gl')->where($where)->setFIeld('status',1)){
			$this->success('审核通过',U('lists'));
		}else{
			$this->error('审核失败，请重新审核');
		}
	}

	/*回复*/
    function review(){
    	$id = I('get.id');
    	if(IS_POST){
    		$model = M('photo_zm_review');
    		$info = $model->create();
    		$info['id'] = $id;
    		$info['status'] = 1;
    		$info['review_time'] = time();
    		if(!$info['reply_content']) $this->error('请输入回复内容');
  			if($model->save($info)){
          $uid = M ( 'public_follow' )->where ( $map )->getField ( 'uid' );
          //推送模版消息
           $template = array(
               'touser' => M ( 'public_follow' )->alias('a')->join('__PHOTO_ZM_REVIEW__ as b on a.uid = b.uid')->where ( array('a.token'=>get_token()) )->getField ( 'a.openid' ),  //根据uid获取用户openid
               'template_id' =>"X185DCiBTyJ7wfKl-SsjAn1PrwIXDLvTSys3tG2uGC0",
               'url' =>addons_url( 'Zmphoto://Wap/infoReview'),
               'topcolor' => "#7B68EE",
               'data' =>array(
                  'first'=>array('value'=>urlencode("管理员回复了你的留言，请赶紧查看"),
                     'color'=>"#743A3A",
                      ),
                   'keyword1'=>array('value'=>urlencode('留言回复'),
                       'color'=>"#ff00000",
                   ),
                   'keyword2'=>array('value'=>urlencode(time_format(time())),
                       'color'=>"#0000ff",
                   ),
                   'remark'=>array('value'=>urlencode("这里是备注"),
                       'color'=>"#008000",
                   ),
               )
           );
          send_template_message(urldecode(json_encode($template)));
  				$this->success('回复成功!',U('lists'));
  			}else{
  				
  				$this->error('请重新回复');
  			}
    		
    	}else{
    		$this->display('Zmphoto/review');
    	}   
}

}